// import { MockMethod } from 'vite-plugin-mock';
const SUCCESS_MESSAGE = '接口连接正常'
const ERROR_MESSAGE = '接口异常'
const userList = [
    {
        name: "admin",
        password: "admin",
        dept: 1,
        depaName: '管理员',
        sex: "male",
        id: 1,
        token: "123456"
    },
    {
        name: "张三",
        password: "zs",
        dept: 2,
        depaName: '测试',
        sex: "male",
        id: 2,
        token: "123456"
    },
    {
        name: "李四",
        password: "ls",
        dept: 2,
        depaName: '测试',
        sex: "male",
        id: 3,
        token: "123456"
    },
]

export default [
    {
        url: '/api/login',
        method: 'post',
        response: ({ body }) => {
            const { userName, password } = body;
            const userInfo = userList.find(item => item.name === userName && item.password === password);
            if (!userInfo) {
                return { code: 201, data: {}, message: '用户名或密码错误' }
            }
            return { code: 200, data: userInfo, message: SUCCESS_MESSAGE }
        },
    },
    {
        url: '/api/getList',
        method: 'post',
        response: (req) => {
            return {
                code: 200,
                data: userList
            };
        },
    },
    {
        url: '/api/getUserInfo',
        method: 'post',
        response: ({ body }) => {
            const { id } = body;
            if (id) {
                const userInfo = userList.find(item => item.id == id);
                if (userInfo) {
                    return { code: 200, data: userInfo, message: SUCCESS_MESSAGE }
                }
                return { code: 201, data: {}, message: ERROR_MESSAGE }
            }
            return { code: 201, data: {}, message: ERROR_MESSAGE }

        },
    },
];
